﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MuaChung.Models;

namespace MuaChung.Controllers
{
    public class ShareController : Controller
    {
        //
        // GET: /Share/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Paging(string type, int currentPage = 1, int pageSize = 10, string param = null)
        {
            PagingModel model = new PagingModel();
            int totalItem;
            switch (type)
            {
                case "allCoupon":
                    {
                        totalItem = CouponModel.GetNumberOfCoupon();
                        if (totalItem == 0)
                        {
                            ViewData["result"] = "NoItem";
                        }
                        model.currentPage = currentPage;
                        model.totalPage = (int)Math.Ceiling((double)totalItem / pageSize);
                        model.url = "/Coupon/ListAllCoupon?";
                        break;
                    }
                case "adminAllCoupon":
                    {
                        totalItem = CouponModel.GetNumberOfCoupon();
                        if (totalItem == 0)
                        {
                            ViewData["result"] = "NoItem";
                        }
                        model.currentPage = currentPage;
                        model.totalPage = (int)Math.Ceiling((double)totalItem / pageSize);
                        model.url = "/Admin/ListAllCoupon?";
                        break;
                    }
                case "allAccount":
                    {
                        totalItem = AccountModel.GetNumberAccount();
                        if (totalItem == 0)
                        {
                            ViewData["result"] = "NoItem";
                        }
                        model.currentPage = currentPage;
                        model.totalPage = (int)Math.Ceiling((double)totalItem / pageSize);
                        model.url = "/Admin/ListAllAccount?";
                        break;
                    }
                case "allQuestion":
                    {
                        totalItem = HelpModel.GetNumberQuestion();
                        if (totalItem == 0)
                        {
                            ViewData["result"] = "NoItem";
                        }
                        model.currentPage = currentPage;
                        model.totalPage = (int)Math.Ceiling((double)totalItem / pageSize);
                        model.url = "/Manager/ListAllQuestion?";
                        break;
                    }
                case "searchCoupon":
                    {
                        totalItem = CouponModel.SearchCoupon(param).Count;
                        if (totalItem == 0)
                        {
                            ViewData["result"] = "NoItem";
                        }
                        model.currentPage = currentPage;
                        model.totalPage = (int)Math.Ceiling((double)totalItem / pageSize);
                        model.url = "/Coupon/SearchCouponResult?keyword="+HttpUtility.UrlEncodeUnicode(param)+"&";
                        break;
                    }
                default:
                    break;
            }
            return View(model);
        }

        public ActionResult WebMenu()
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewData["userRole"] = AccountModel.FindByUsername(User.Identity.Name).Role;
            }
            else
            {
                ViewData["userRole"] = "Undefine";
            }

            return View();
        }
    }
}
